package ObserverModel2;

/**
 * Created by Lenovo on 2017/5/15.
 */
public class Observer implements Observable {

    /**
     * 观察者
     */
    private String name;
    /**
     * 具体主题
     */
    private ConcreteSubject subject;

    public Observer(String name, ConcreteSubject subject) {
        this.name = name;
        this.subject = subject;

        // 绑定观察者
        this.subject.Attach(this);

        Update();
    }

    @Override
    public void Update() {
        String str = String.format("name: %s subject: %s", name, subject.toString());
        System.out.println(str);
    }
}
